
import { AppstoreOutlined, MailOutlined, SettingOutlined } from '@ant-design/icons';
import { Menu } from 'antd';
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';

function getItem(label, key, icon, children, type) {
    return {
        key,
        icon,
        children,
        label,
        type,
    };
}

function ComMenu() {
    var [items, getItems] = useState([
        getItem('首页', 'sub1', <MailOutlined />),
    ]);
    let Naviga = useNavigate()
    useEffect(() => {
        // console.log(sessionStorage.getItem('user'));
        if (sessionStorage.getItem('user')) {
            // console.log(JSON.parse(sessionStorage.getItem('user')), '哈哈房价肯定会就卡复活');
            let asidelist = JSON.parse(sessionStorage.getItem('user')).menus
            let a = asidelist.map((item, index) => {
                return getItem(item.title, index,<SettingOutlined/>, item.children.map(itt => {
                    return getItem(itt.title, itt.url)
                }))
            })

            getItems([
                getItem('首页', 'sub1', <MailOutlined />),
                ...a
            ])
            // console.log(asidelist);
        } else {
            // console.log('23哇45345345345345345355346');
        }
    }, [])

    // console.log(naviga);
    const onClick = (e) => {
        // console.log('click ', e);
        console.log(e.key,'88888888888888');
        if (e.key == '/setshop') {
            Naviga('shop')
        }
        if (e.key == '/setpeople') {
            Naviga('people')
        }

    };
    return (
        <Menu
            onClick={onClick}
            style={{
                width: 200,
                height: 550
            }}
            defaultSelectedKeys={['1']}
            defaultOpenKeys={['sub1']}
            mode="inline"
            items={items}
        />
    );
};

export default ComMenu;